package com.ruoyi.common.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * <p>
 * 支付交易记录表，记录所有支付、退款和提现的交易信息
 * </p>
 *
 * @author jiabao
 * @since 2025-06-25
 */
@Getter
@Setter
@ToString
@Builder
@AllArgsConstructor
@NoArgsConstructor
@TableName("business_payment_records")
@ApiModel(value = "PaymentRecords对象", description = "支付交易记录表，记录所有支付、退款和提现的交易信息")
public class PaymentRecords implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 记录ID，主键自增
     */
    @ApiModelProperty("记录ID，主键自增")
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 关联business_orders表的订单ID
     */
    @TableField("order_id")
    @ApiModelProperty("关联business_orders表的订单ID")
    private Long orderId;

    /**
     * 关联business_users表的用户ID
     */
    @TableField("user_id")
    @ApiModelProperty("关联business_users表的用户ID")
    private Long userId;

    /**
     * 支付/退款金额(单位：元)
     */
    @TableField("amount")
    @ApiModelProperty("支付/退款金额(单位：元)")
    private BigDecimal amount;

    /**
     * 类型：1-支付 2-退款 3-提现
     */
    @TableField("payment_type")
    @ApiModelProperty("类型：WECHAT POINTS")
    private String paymentType;

    @TableField("operation_type")
    @ApiModelProperty("操作类型")
    private String operationType;

    @Getter
    public enum PAYMENT_TYPE {
        WECHAT("微信", "WECHAT"),
        POINTS("积分", "POINTS");

        private final String desc;
        private final String value;

        PAYMENT_TYPE(String desc, String value) {
            this.desc = desc;
            this.value = value;
        }

        // 通过value获取枚举实例
        public static PAYMENT_TYPE fromValue(String value) {
            for (PAYMENT_TYPE type : values()) {
                if (type.value.equals(value)) {
                    return type;
                }
            }
            throw new IllegalArgumentException("未知的状态类型: " + value);
        }
    }



    @Getter
    public enum OPERATION_TYPE {
        PAYMENT("付款", "PAYMENT"),
        REFUND("退款", "REFUND"),
        WAITING_COMMENT("提现", "WITHDRAWAL");

        private final String desc;
        private final String value;

        OPERATION_TYPE(String desc, String value) {
            this.desc = desc;
            this.value = value;
        }

        // 通过value获取枚举实例
        public static OPERATION_TYPE fromValue(String value) {
            for (OPERATION_TYPE type : values()) {
                if (type.value.equals(value)) {
                    return type;
                }
            }
            throw new IllegalArgumentException("未知的状态类型: " + value);
        }
    }


    /**
     * 状态：0-处理中 1-成功 2-失败
     */
    @TableField("status")
    @ApiModelProperty("状态：0-处理中 1-成功 2-失败")
    private Integer status;

    /**
     * 微信支付交易单号(用于对账和查询)
     */
    @TableField("wx_transaction_id")
    @ApiModelProperty("微信支付交易单号(用于对账和查询)")
    private String wxTransactionId;

    /**
     * 支付/退款时间(记录交易完成时间)
     */
    @TableField("payment_time")
    @ApiModelProperty("支付/退款时间(记录交易完成时间)")
    private LocalDateTime paymentTime;

    /**
     * 创建时间
     */
    @ApiModelProperty("创建时间")
    @TableField("created_at")
    private LocalDateTime createdAt;

    /**
     * 最后更新时间
     */
    @TableField("updated_at")
    @ApiModelProperty("最后更新时间")
    private LocalDateTime updatedAt;



}
